.qa-job-base:
  image: ${REGISTRY_HOST}/${REGISTRY_GROUP}/gitlab-build-images/debian-${DEBIAN_VERSION}-ruby-${RUBY_VERSION}:bundler-2.3-chrome-${CHROME_VERSION}-docker-${DOCKER_VERSION}
  extends:
    - .default-retry
    - .qa-cache
  stage: test
  needs: []
  variables:
    USE_BUNDLE_INSTALL: "false"
    SETUP_DB: "false"
  before_script:
    - !reference [.default-before_script, before_script]
    - cd qa && bundle install

.e2e-trigger-base:
  extends: .production  # this makes sure GITLAB_ALLOW_SEPARATE_CI_DATABASE is passed to the child pipeline
  stage: qa
  variables:
    # This is needed by `trigger-omnibus-env` (`.gitlab/ci/package-and-test/main.gitlab-ci.yml`).
    PARENT_PIPELINE_ID: $CI_PIPELINE_ID
    SKIP_MESSAGE: Skipping package-and-test due to mr containing only quarantine changes!
    GITLAB_QA_IMAGE: "${CI_REGISTRY_IMAGE}/gitlab-ee-qa:${CI_COMMIT_SHA}"
    RUN_WITH_BUNDLE: "true"  # instructs pipeline to install and run gitlab-qa gem via bundler
    QA_PATH: qa  # sets the optional path for bundler to run from
    DYNAMIC_PIPELINE_YML: package-and-test-pipeline.yml  # yml files are generated by scripts/generate-e2e-pipeline script
  inherit:
    variables:
      - CHROME_VERSION
      - RUBY_VERSION
      - DOCKER_VERSION
      - DEBIAN_VERSION
      - REGISTRY_GROUP
      - REGISTRY_HOST
  trigger:
    strategy: depend
    forward:
      yaml_variables: true
      pipeline_variables: true
    include:
      - artifact: $DYNAMIC_PIPELINE_YML
        job: e2e-test-pipeline-generate

qa:internal:
  extends:
    - .qa-job-base
    - .qa:rules:internal
  script:
    - bundle exec rspec -O .rspec_internal

qa:internal-as-if-foss:
  extends:
    - qa:internal
    - .qa:rules:internal-as-if-foss
    - .as-if-foss

qa:master-auto-quarantine-dequarantine:
  extends:
    - .qa-job-base
  rules:
    - if: '$QA_TRIGGER_AUTO_QUARANTINE =~ /true|yes|1/i'
  script:
    - bundle exec confiner -r .confiner/master.yml
  allow_failure: true

qa:update-qa-cache:
  extends:
    - .qa-job-base
    - .qa-cache-push
    - .shared:rules:update-cache
  stage: prepare
  script:
    - echo "Cache has been updated and ready to be uploaded."

trigger-omnibus:
  stage: qa
  extends:
    - .qa:rules:trigger-omnibus
  needs:
    - trigger-omnibus-env
    - build-assets-image
  inherit:
    variables: false
  variables:
    GITALY_SERVER_VERSION: $GITALY_SERVER_VERSION
    GITLAB_ELASTICSEARCH_INDEXER_VERSION: $GITLAB_ELASTICSEARCH_INDEXER_VERSION
    GITLAB_KAS_VERSION: $GITLAB_KAS_VERSION
    GITLAB_METRICS_EXPORTER_VERSION: $GITLAB_METRICS_EXPORTER_VERSION
    GITLAB_PAGES_VERSION: $GITLAB_PAGES_VERSION
    GITLAB_SHELL_VERSION: $GITLAB_SHELL_VERSION
    GITLAB_WORKHORSE_VERSION: $GITLAB_WORKHORSE_VERSION
    GITLAB_VERSION: $CI_COMMIT_SHA
    GITLAB_ASSETS_TAG: $GITLAB_ASSETS_TAG
    IMAGE_TAG: $CI_COMMIT_SHA
    TOP_UPSTREAM_SOURCE_PROJECT: $CI_PROJECT_PATH
    SECURITY_SOURCES: $SECURITY_SOURCES
    CACHE_UPDATE: $OMNIBUS_GITLAB_CACHE_UPDATE
    USE_OLD_RUBY_VERSION: "true"
    CACHE_EDITION: "GITLAB_RUBY3_0"
    NEXT_RUBY_VERSION: "3.1.4"
    BUILD_ON_ALL_OS: $OMNIBUS_GITLAB_BUILD_ON_ALL_OS
    SKIP_QA_TEST: "true"
    ee: $EE
  trigger:
    project: gitlab-org/build/omnibus-gitlab-mirror
    branch: $TRIGGER_BRANCH
    strategy: depend

# Same as trigger-omnibus but is manual and runs follow-up-e2e:package-and-test-ee automatically right after
trigger-omnibus-and-follow-up-e2e:
  extends:
    - trigger-omnibus
    - .qa:rules:manual-omnibus-and-follow-up-e2e

trigger-omnibus as-if-foss:
  extends:
    - trigger-omnibus
    - .qa:rules:trigger-omnibus-ce
  needs:
    - trigger-omnibus-env as-if-foss
    - build-assets-image as-if-foss
  variables:
    # Override gitlab repository so that omnibus doesn't use foss repository for CE build
    GITLAB_ALTERNATIVE_REPO: $CI_PROJECT_URL

e2e:package-and-test-ee:
  extends:
    - .e2e-trigger-base
    - .qa:rules:package-and-test-ee
  needs:
    - build-qa-image
    - trigger-omnibus
    - e2e-test-pipeline-generate
  variables:
    RELEASE: "${REGISTRY_HOST}/${REGISTRY_GROUP}/build/omnibus-gitlab-mirror/gitlab-ee:${CI_COMMIT_SHA}"
    QA_RUN_TYPE: e2e-package-and-test
    PIPELINE_NAME: E2E Omnibus GitLab EE

# Same as e2e:package-and-test-ee but runs automatically after trigger-omnibus-and-follow-up-e2e
follow-up-e2e:package-and-test-ee:
  extends:
    - .e2e-trigger-base
    - .qa:rules:follow-up-e2e
  needs:
    - build-qa-image
    - trigger-omnibus-and-follow-up-e2e
    - e2e-test-pipeline-generate
  variables:
    RELEASE: "${REGISTRY_HOST}/${REGISTRY_GROUP}/build/omnibus-gitlab-mirror/gitlab-ee:${CI_COMMIT_SHA}"
    QA_RUN_TYPE: e2e-package-and-test
    PIPELINE_NAME: E2E Omnibus GitLab EE

e2e:post-run-e2e-message:
  extends:
    - .predictive-job
    - .qa:rules:post-run-e2e-message
  stage: qa
  variables:
    ENV_FILE: $CI_PROJECT_DIR/qa_tests_vars.env
  image: ${GITLAB_DEPENDENCY_PROXY_ADDRESS}ruby:${RUBY_VERSION}
  before_script:
    - source scripts/utils.sh
    - install_gitlab_gem
  script:
    - scripts/generate-message-to-run-e2e-pipeline.rb
  needs:
    - e2e-test-pipeline-generate
    - trigger-omnibus-env
    - build-assets-image
  artifacts:
    expire_in: 1 day
    paths:
      - "${CI_PROJECT_DIR}/qa_tests_vars.env"

e2e:package-and-test-ce:
  extends:
    - e2e:package-and-test-ee
    - .qa:rules:package-and-test-ce
  needs:
    - build-qa-image as-if-foss
    - trigger-omnibus as-if-foss
    - e2e-test-pipeline-generate
  variables:
    FOSS_ONLY: "1"
    RELEASE: ${REGISTRY_HOST}/${REGISTRY_GROUP}/build/omnibus-gitlab-mirror/gitlab-ce:${CI_COMMIT_SHA}
    GITLAB_QA_IMAGE: ${CI_REGISTRY_IMAGE}/gitlab-ce-qa:${CI_COMMIT_SHA}
    QA_RUN_TYPE: e2e-package-and-test-ce
    PIPELINE_NAME: E2E Omnibus GitLab CE

e2e:package-and-test-nightly:
  extends:
    - .e2e-trigger-base
    - .qa:rules:package-and-test-nightly
  needs:
    - build-qa-image
    - trigger-omnibus
    - e2e-test-pipeline-generate
  variables:
    GITLAB_SEMVER_VERSION: $GITLAB_SEMVER_VERSION
    QA_RUN_TYPE: nightly
    PIPELINE_NAME: E2E Omnibus GitLab Nightly
    DYNAMIC_PIPELINE_YML: package-and-test-nightly-pipeline.yml

e2e:test-on-gdk:
  extends:
    - .e2e-trigger-base
    - .qa:rules:e2e:test-on-gdk
  stage: qa
  needs:
    - build-gdk-image
    - e2e-test-pipeline-generate
  variables:
    QA_RUN_TYPE: e2e-test-on-gdk
    PIPELINE_NAME: E2E GDK
    DYNAMIC_PIPELINE_YML: test-on-gdk-pipeline.yml
    SKIP_MESSAGE: Skipping test-on-gdk due to mr containing only quarantine changes!
    GDK_IMAGE: "${CI_REGISTRY_IMAGE}/gitlab-qa-gdk:${CI_COMMIT_SHA}"
